/*-------------------------------------------------------------------------
   Copyright (C) 2010 One Laptop per Child
-------------------------------------------------------------------------*/

#ifndef MPPT_H
#define MPPT_H

// Choose which method to use for squeal detect
#define USE_POLLING_SQUEAL 0

extern unsigned char	mppt_flags;
#define			mppt_is_enabled		(1<<0)			// 1: enable
#define			mppt_is_active		(1<<1)			// 1: modulating power
#define			mppt_is_chg_ok		(1<<3)			// 1: ok to enable charging
#define			mppt_is_squeal		(1<<4)			// 1: squeal detected
#define			mppt_frontside		(1<<5)			// Which side of hill we are checking
// current sensor are we reading
#define			mppt_Isense_sys		(1<<6)			// 0: battery 1; Isystem (switcher output)
#define			mppt_verbose		(1<<7)			// display decision info each loop

void mppt_init_module(void);
void mppt_cmd_read_active(void);
void mppt_cmd_read_limit(void);
void mppt_cmd_set_limit(unsigned char);
void mppt_cmd_enable(char);
void mppt_process(void);
void mppt_init_defaults(void);
void mppt_nice_log(void);

void mppt_set_limit_v2(unsigned char value);
void mppt_set_minpower_limit(unsigned char value);
void mppt_set_start_power_limit(unsigned char value);
void mppt_set_maxpower_limit(unsigned char value);
void mppt_change_power_limit(int dP);

unsigned char mppt_get_minpower_limit(void);
unsigned char mppt_get_start_power_limit(void);
unsigned char mppt_get_maxpower_limit(void);

unsigned char mppt_get_limit(void);

#define MPPT_POWER_FULL PWM_14_BIT_MAX   // FIXME

#define MPPT_ENABLE_DEFAULT	0

#endif
